package cn.edu.sgu.www.mhxysy.controller.fabao;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.fabao.FabaoLiangyiAttributeCategoryDTO;
import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoLiangyiAttributeCategory;
import cn.edu.sgu.www.mhxysy.pager.fabao.FabaoLiangyiAttributeCategoryPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.fabao.FabaoLiangyiAttributeCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "法宝两仪管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/fabao_liangyi_attribute_category", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class FabaoLiangyiAttributeCategoryController {

	private final FabaoLiangyiAttributeCategoryService fabaoLiangyiAttributeCategoryService;

	@Autowired
	public FabaoLiangyiAttributeCategoryController(FabaoLiangyiAttributeCategoryService fabaoLiangyiAttributeCategoryService) {
		this.fabaoLiangyiAttributeCategoryService = fabaoLiangyiAttributeCategoryService;
	}

	@ApiOperation("添加法宝两仪")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated FabaoLiangyiAttributeCategoryDTO fabaoLiangyiAttributeCategoryDTO) {
		fabaoLiangyiAttributeCategoryService.insert(fabaoLiangyiAttributeCategoryDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID修改法宝两仪信息")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated FabaoLiangyiAttributeCategoryDTO fabaoLiangyiAttributeCategoryDTO) {
		fabaoLiangyiAttributeCategoryService.updateById(fabaoLiangyiAttributeCategoryDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过ID查询法宝两仪信息")
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<FabaoLiangyiAttributeCategory> selectById(
			@ApiParam(name = "id", value = "法宝两仪ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		FabaoLiangyiAttributeCategory fabaoLiangyiAttributeCategory = fabaoLiangyiAttributeCategoryService.selectById(id);

		return JsonResult.success(null, fabaoLiangyiAttributeCategory);
	}

	@ApiOperation("查询法宝的两仪信息")
	@RequestMapping(value = "/selectByFabaoId", method = RequestMethod.GET)
	public JsonResult<List<FabaoLiangyiAttributeCategory>> selectByFabaoId(
			@ApiParam(name = "fabaoId", value = "法宝类型ID", required = false)
			@RequestParam(required = false) Integer fabaoId) {
		List<FabaoLiangyiAttributeCategory> list = fabaoLiangyiAttributeCategoryService.selectByFabaoId(fabaoId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("分页查询法宝两仪列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<FabaoLiangyiAttributeCategory>> selectByPage(FabaoLiangyiAttributeCategoryPager pager) {
		Page<FabaoLiangyiAttributeCategory> page = fabaoLiangyiAttributeCategoryService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}